package com.SMP.controller.class_room;


import java.util.List;


import com.SMP.model.Room;
import com.SMP.model.Msg;
import com.SMP.service.class_room.RoomService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class RoomConfigController {
    /**
     * @author GJ
     */
    @Autowired
    RoomService roomService;
    /**
     * @author GJ
    //	 * @param 查询所有房间
     * */
    @RequestMapping("/selAllRoom")
    @ResponseBody
    public Msg selAllRoom(@RequestParam(value = "pn" ,defaultValue = "1") Integer pn){
        PageHelper.startPage(pn, 5);
        List<Room> list=roomService.selAllRoom();
        PageInfo<Room> page=new PageInfo<Room>(list,  5);
        return Msg.success().add("pageInfo", page);
    }
    /**
     * @author GJ
    //	 * @param 查询房间详细信息
     * */
    @RequestMapping(value="/selRoom", method=RequestMethod.GET)
    @ResponseBody
    public Msg selRoom(String id){
        Room room=roomService.selRoom(id);
        return Msg.success().add("room",room);
    }
    /**
     * @author GJ
    //	 * @param 添加房间
     * */
    @RequestMapping("/addRoom")
    @ResponseBody
    public Msg addRoom(Room room){

        int a=roomService.addRoom(room);

        if (a==1) {
            return Msg.success();
        }else{
            return  Msg.fail();
        }
    }


    /**
     * @author GJ
    //	 * @param 修改房间
     * */
    @RequestMapping("/updRoom")
    @ResponseBody
    public Msg updRoom(Room room){

        int a=roomService.updRoom(room);
        if (a==1) {
            return Msg.success();
        }else{
            return  Msg.fail();
        }
    }
    /**
     * @author GJ
    //	 * @param 删除房间
     * */
    @RequestMapping("/delRoom")
    @ResponseBody
    public Msg delRoom(@RequestParam(value = "id")String id){
        int a = roomService.delRoomF(id);
        if (a==1) {
            return Msg.success();
        } else {
            return Msg.fail();
        }
    }
    /**
     * @author TSY
    //	 * @param 按照房间编号查询房间
     * */
    @RequestMapping("/selRoomById")
    @ResponseBody
    public Msg selRoomById(@RequestParam(value = "pn" ,defaultValue = "1") Integer pn,@RequestParam(value = "id") String id){
        PageHelper.startPage(pn, 5);
        List<Room> list=roomService.selRoomById(id);
        PageInfo<Room> page=new PageInfo<Room>(list,  5);
        return Msg.success().add("pageInfo", page);
    }
    /**
     * @author TSY
    //	 * @param 按照房间名查询房间
     * */
    @RequestMapping("/selRoomByName")
    @ResponseBody
    public Msg selRoomByName(@RequestParam(value = "pn" ,defaultValue = "1") Integer pn,@RequestParam(value = "name") String name){
        PageHelper.startPage(pn, 5);
        List<Room> list=roomService.selRoomByName(name);
        PageInfo<Room> page=new PageInfo<Room>(list,  5);
        return Msg.success().add("pageInfo", page);
    }
    /**
     * @author TSY
    //	 * @param 按照设备Id查询房间
     * */
    @RequestMapping("/selRoomByEid")
    @ResponseBody
    public Msg selRoomByEid(@RequestParam(value = "pn" ,defaultValue = "1") Integer pn,@RequestParam(value = "equipmentId") String equipmentId){
        PageHelper.startPage(pn, 5);
        List<Room> list=roomService.selRoomByEid(equipmentId);
        PageInfo<Room> page=new PageInfo<Room>(list,  5);
        return Msg.success().add("pageInfo", page);
    }
    /**
     * @author TSY
    //	 * @param 按照房间使用情况查询房间
     * */
    @RequestMapping("/selRoomByUse")
    @ResponseBody
    public Msg selRoomByUse(@RequestParam(value = "pn" ,defaultValue = "1") Integer pn,@RequestParam(value = "roomUse") String roomUse){
        PageHelper.startPage(pn, 5);
        List<Room> list=roomService.selRoomByUse(roomUse);
        PageInfo<Room> page=new PageInfo<Room>(list,  5);
        return Msg.success().add("pageInfo", page);
    }
    /**
     * @author TSY
    //	 * @param 按照房间类型查询房间
     * */
    @RequestMapping("/selRoomByType")
    @ResponseBody
    public Msg selRoomByType(@RequestParam(value = "pn" ,defaultValue = "1") Integer pn,@RequestParam(value = "roomType") String roomType){
        PageHelper.startPage(pn, 5);
        List<Room> list=roomService.selRoomByType(roomType);
        PageInfo<Room> page=new PageInfo<Room>(list,  5);
        return Msg.success().add("pageInfo", page);
    }
}

